﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

 namespace VatGia
{
     //public delegate void ShowFormSP();
    public partial class FormDangNhap : Form
    {
        //public static string username = "";
        //public static string hoten = "";

        //public event ShowFormSP Showfromsp;
        private FormMain1 frm;
        public FormDangNhap(FormMain1 frm)
        {
            this.frm = frm;
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {
            
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
           
            this.Close();

        }

        private void txtPass_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                DataService dservice = new DataService();
                DataTable dt = new DataTable();
                dservice.Connect();

                //them nguoi dung moi
                SqlParameter[] parameters = new SqlParameter[2];
               // parameters = new SqlParameter[2];
                parameters[0] = new SqlParameter("@username", txtUser.Text);
                parameters[1] = new SqlParameter("@pass", txtPass.Text);
               dt =   dservice.ExcuteProcedureGetTable("sp_Login", parameters, null);

                dservice.Disconnect();
                if (dt.Rows.Count > 0)
                {
                   //pb.username =  dt.Rows[0]["UserName"].ToString();
                   //pb.hoten = dt.Rows[0]["HoTen"].ToString();
                    Public_variable.Username = dt.Rows[0]["UserName"].ToString();
                    Public_variable.Hoten = dt.Rows[0]["HoTen"].ToString(); 
                    //Dang nhap thanh cong,xu ly tiep
                    frm.load();
                }
                else {
                    MessageBox.Show("Sai username hoặc password !");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            
        }
    }
}
